import Mock from "mockjs";
// var Mock = require("mockjs");
const flName = [
  "月季花",
  "梅花",
  "桃花",
  "牡丹",
  "海棠",
  "玉兰",
  "木笔",
  "紫荆",
  "连翘",
  "金钟",
  "丁香",
  "紫藤",
  "春鹃",
  "杜鹃花",
  "石榴花",
  "含笑花",
  "白兰花",
  "茉莉花",
  "栀子花",
  "桂花",
  "木芙蓉",
  "腊梅",
  "免牙红",
  "银芽柳",
  "山茶花",
  "迎春花",
];

const type = ["满500减30", "满200减10", "满700见60"];

let { data } = Mock.mock({
  "data|307": [
    {
      "goodsId|+1": 100,
      date: /200206\d{6}/,
      "name|1": flName,
      "freight|10-30": 10,
      "price|300-600": 300,
      supplier: "@cparagraph(1)",
      "activity|1": type,
    },
  ],
});

class ProductServer {
  getData({ page, size }) {
    return new Promise((resolve) => {
      // fen页截取
      const result = data.slice((page - 1) * size, page * size);
      resolve({
        status: 0,
        result: result,
        count: data.length,
      });
    });
  }

  removeData({ goodsId }) {
    return new Promise((resolve) => {
      data = data.filter((item) => item.goodsId !== goodsId);
      resolve({
        status: 0,
        msg: "删除成功",
      });
    });
  }
}

const product = new ProductServer();
export default product;

// console.log(data);
